package com.jishuo.nontax.bfc.service;

import com.github.pagehelper.PageHelper;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.service.SequenceService;
import com.jishuo.base.util.ExportSXSSFUtil;
import com.jishuo.base.util.GTimeUtil;
import com.jishuo.base.util.StringUtil;
import com.jishuo.nontax.bean.bank.Waitaffirm;
import com.jishuo.nontax.bean.bank.WaitaffirmXML;
import com.jishuo.nontax.bean.message.*;
import com.jishuo.nontax.bean.vo.BankStationVO;
import com.jishuo.nontax.bean.vo.BankVO;
import com.jishuo.nontax.bean.vo.CantonVO;
import com.jishuo.nontax.bean.vo.WaitaffirmVO;
import com.jishuo.nontax.bfc.dao.BankMapper;
import com.jishuo.nontax.bfc.dao.BaseDataMapper;
import com.jishuo.nontax.bfc.dao.WaitaffirmMapper;
import com.jishuo.nontax.bfc.pzk.PzkService;
import com.jishuo.nontax.bfc.tlq.MessageService;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author hlp
 * @date 2023/2/2 10:47
 * @Description:
 */
@Service
public class WaitaffirmService {

    private static Logger logger = LoggerFactory.getLogger(WaitaffirmService.class);
    @Resource
    private WaitaffirmMapper waitaffirmMapper;
    @Resource
    private BankMapper bankMapper;
    @Resource
    private SequenceService sequenceService;
    @Resource
    private MessageService messageService;
    @Resource
    private PzkService  pzkService;
    @Resource
    private ChargeBillService chargeBillService;
    @Resource
    private BaseDataMapper baseDataMapper;

    /**
     * @author hlp
     * @date 2023/3/9 10:24
     * @Description: 待查收入分页列表
     */
    public List<WaitaffirmVO> findWaitaFfirmPage(WaitaffirmVO waitaffirmVO, Pagination pagination) {
        // 当单页条数大于零时，启用分页
        if (pagination.getRows() > 0) PageHelper.startPage(pagination.getPage(), pagination.getRows());
        return this.waitaffirmMapper.findWaitAffirmPage(waitaffirmVO);
    }

    /** web 新增 */
    public BaseResult saveWaitAffirm(WaitaffirmVO waitaffirmVO) {
        WaitaffirmVO vo =waitaffirmMapper.selectSwaitaffirm(waitaffirmVO.getBankaffirm(), waitaffirmVO.getBankid(), waitaffirmVO.getPaybankdt().substring(0, 10));
        if (vo != null) return new BaseResult(ErrorCodeEnum.CUSTOM_ERR.getCode(), "此交易流水已存在");
        try {
            waitaffirmVO.setBillstate(0);
            waitaffirmVO.setIssend(0);
            waitaffirmVO.setWaitaffirmid(sequenceService.getNextSeq("FSWAITAFFIRMSEQ"));
            if(waitaffirmMapper.insertWaitaffirm(waitaffirmVO)>0){
                return new BaseResult();
            } else {
                return new BaseResult(ErrorCodeEnum.DB_ERR);
            }
        } catch (Exception e) {
            logger.info("保存待查错误。", e);
            return new BaseResult(ErrorCodeEnum.SYS_ERR.getCode(), e.getMessage());
        }
    }

    /** web 保存 */
    public BaseResult updateWaitAffirm(WaitaffirmVO waitaffirmVO) {
        waitaffirmVO.setIssend(0);
        if(waitaffirmMapper.updateWaitaffirm(waitaffirmVO)>0){
            return new BaseResult();
        }
        return new BaseResult(ErrorCodeEnum.DB_ERR);
    }

    /** web 删除 */
    public BaseResult deletewaitaffirm(String waitaffirmids) {
        String[] ids = waitaffirmids.split(",");
        if(waitaffirmMapper.deleteWaitAffirm(ids)>0){
            return new BaseResult();
        }
        return new BaseResult(ErrorCodeEnum.DB_ERR);
    }

    /**
     * 保存，view页面
     * @author hlp
     * @date 2023/2/2 14:45
     * @Description: 修改添加银行上传待查信息，不发送财政
     */
    public BaseResult setWaitaffirm(WaitaffirmVO waitaffirmVO) {
        try {
            int paywayid = sequenceService.getPayWayID(waitaffirmVO.getPaywaycode());
            BankVO bank = bankMapper.findBankVO(waitaffirmVO.getAccountcode());

            waitaffirmVO.setCantonid(bank.getCantonid());
            waitaffirmVO.setPayway(paywayid);
            waitaffirmVO.setBankid(bank.getBankid());
            waitaffirmVO.setIssend(0);
            waitaffirmVO.setHxbankaffirm(waitaffirmVO.getBankaffirm());
            waitaffirmVO.setBillstate(0);

            WaitaffirmVO vo =waitaffirmMapper.selectSwaitaffirm(waitaffirmVO.getBankaffirm(), waitaffirmVO.getBankid(), waitaffirmVO.getPaybankdt().substring(0, 10));
            if (vo == null) {
                waitaffirmVO.setWaitaffirmid(sequenceService.getNextSeq("FSWAITAFFIRMSEQ"));
                if (waitaffirmMapper.insertWaitaffirm(waitaffirmVO) > 0) return new BaseResult();
            } else {
                waitaffirmVO.setWaitaffirmid(vo.getWaitaffirmid());
                if (waitaffirmMapper.updateWaitaffirm(waitaffirmVO) > 0) return new BaseResult();
            }
            return BaseResult.CustomErr("写入失败");
        } catch (Exception e) {
            logger.info("失败" + e.toString(), e);
            return new BaseResult(ErrorCodeEnum.DB_ERR);
        }
    }

    /**
     * 发送账户全部待查
     * @param accountcode 账号
     * @param paybankdt 日期，yyyy-mm-dd
     * @return
     */
    public BaseResult sendWaitAffirm(String accountcode, String paybankdt) {
        BankVO bank = bankMapper.findBankVO(accountcode);
        if (bank == null) return new BaseResult(ErrorCodeEnum.CUSTOM_ERR.getCode(), accountcode + "账户不存在");
        return sendWaitAffirm(bank.getBankid(), paybankdt);
    }

    /**
     * 发送账户全部待查
     * @param bankid 账户id
     * @param paybankdt 日期，yyyy-mm-dd
     * @return
     */
    public BaseResult sendWaitAffirm(Long bankid, String paybankdt) {
        try {
            //  根据(bankid 银行帐户ID)  、(paybankdt 收款时间) 查询银行上传待查表
            List<WaitaffirmVO> list = waitaffirmMapper.findSendWaitaffirm(bankid, paybankdt);
            if (list.size() == 0) return new BaseResult();

            List<BankStationVO> stationList = baseDataMapper.findBankStationView(null, 1);
            return this.sendWaitAffirm(list, stationList);
        } catch (Exception e) {
            logger.info("发送待查收入错误。", e);
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR.getCode(), "发送待查收入失败：" + e.toString());
        }
    }

    private BaseResult sendWaitAffirm(List<WaitaffirmVO> waitList, List<BankStationVO> stationList) throws Exception {
        ArrayList<SetWaitaffirmDTO> waitDto = new ArrayList<>();
        BankVO bank = null;
        CantonVO canton = null;
        for (WaitaffirmVO vo : waitList) {
            SetWaitaffirmDTO waitaffirm = vo.getSetWaitaffirmDTO();
            for (BankStationVO station : stationList) {
                if (station.getBankstationcode().equals(vo.getBankstation())) {
                    waitaffirm.setBankstation(station.getBankstationname());
                    vo.setBankstation(station.getBankstationname()); // 跟新，发凭证库用
                    break;
                }
            }
            waitDto.add(waitaffirm);
            // 更新账户、区划
            if (bank == null || bank.getBankid() != vo.getBankid()) {
                bank = this.bankMapper.getBankVo(vo.getBankid());
            }
            if (bank != null) {
                vo.setPayeeaccountcode(bank.getAccountcode());
                vo.setPayeeaccountname(bank.getAccountname());
                vo.setPayeebankname(bank.getBankname());
            }
            if (canton == null || canton.getCantonid() != vo.getCantonid()) {
                canton = this.baseDataMapper.getCantonByID(vo.getCantonid());
            }
            if (canton != null) {
                vo.setCantoncode(canton.getCantoncode());
                vo.setCantonname(canton.getCantonname());
            }
        }
        if (waitDto.size() > 0) {
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");

            SetWaitaffirm waitaffirm = new SetWaitaffirm();
            waitaffirm.setWaitaffirm(waitDto);
            //发送到财政
            messageService.sendMessage("SETWAITAFFIRM", messageid, waitaffirm, "2.2");
            // 写凭证
            pzkService.savePzmsg("SETWAITAFFIRMPZK", waitList);
        }
        return new BaseResult();
    }

    /**
     * 发送指定待查
     * @param billids 需要发送的数据id列表
     * @return
     */
    public BaseResult sendWaitAffirm(String billids) {
        try {
            String[] ids = billids.split(",");
            //  根据(bankid 银行帐户ID)  、(paybankdt 收款时间) 查询银行上传待查表
            List<WaitaffirmVO> list = waitaffirmMapper.findWaitaffirmByIds(ids);
            if (list.size() == 0) return new BaseResult();

            List<BankStationVO> stationList = baseDataMapper.findBankStationView(null, 1);
            return this.sendWaitAffirm(list, stationList);
        } catch (Exception e) {
            logger.info("发送待查收入错误。", e);
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR.getCode(), "发送待查收入失败：" + e.toString());
        }
    }

    /**
     * 清理财政端待查收入
     * @param accountcode 账号
     * @param paybankdt 日期，yyyy-mm-dd
     * @param bankid 账号id
     * @return
     */
    public BaseResult cleanWaitaffirm(String accountcode, String paybankdt, long bankid) {
        try {
            if (bankid == 0) {
                BankVO bank = bankMapper.findBankVO(accountcode);
                if (bank == null) return new BaseResult(ErrorCodeEnum.CUSTOM_ERR.getCode(), "账户不存在");
                bankid = bank.getBankid();
            }
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");
            CleanWaitaffirm waitaffirm = new CleanWaitaffirm();
            waitaffirm.setBankid(String.valueOf(bankid));
            waitaffirm.setBankaccount(accountcode);
            waitaffirm.setPaybankdt(paybankdt);

            //发送到财政
            messageService.sendMessage("CLEANWAITAFFIRM", messageid, waitaffirm, "2.0");
            // 写凭证
            pzkService.savePzmsg("CLEANWAITAFFIRMPZK", waitaffirm);

            return new BaseResult();
        } catch (Exception e) {
            logger.info("清理待查收入失败：" + e.toString(), e);
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR.getCode(), "处理失败：" + e.toString());
        }
    }

    /**
     * 获取已对账产生待查.账户id，账号，流水，日期
     * @param waitaffirmvo
     * @return
     */
    public BaseResult regetWaitaffirm(WaitaffirmVO waitaffirmvo) {
        try {
            String paybankdt = waitaffirmvo.getPaybankdt();
            if (paybankdt.length() > 10) paybankdt = paybankdt.substring(0, 10);
            BankVO bank = bankMapper.findBankVO(waitaffirmvo.getAccountcode());
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");

            RegetWaitaffirm waitaffirm = new RegetWaitaffirm();
            waitaffirm.setBankid(StringUtil.toStr(bank.getBankid()));
            waitaffirm.setBankaccount(bank.getAccountcode());
            waitaffirm.setPaybankdt(paybankdt);
            waitaffirm.setBankaffirm(waitaffirmvo.getBankaffirm());

            //发送到财政
            boolean suc = messageService.sendAndRecvMessage("REGETWAITAFFIRM", messageid, waitaffirm, "2.2");

            if (suc) {
                //xml解析器
                Serializer serializer = new Persister();
                //xml转换器
                StringWriter sw = new StringWriter();
                WaitaffirmXML waitXml = new WaitaffirmXML();
                waitXml.setWaitaffirm(waitaffirmMapper.findWaitaffirmReget(waitaffirmvo));
                serializer.write(waitXml, sw);
                return new BaseResult(sw.toString());
            }
            return new BaseResult();
        } catch (Exception e) {
            logger.info("失败：" + e.toString());
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }
    }

    /**
     * 结束财政返回已对账待查，V2.0
     * @param data 报文
     * @param info
     * @param sn
     */
    public void sendRegetWaitaffirm(String data, String info, String sn) {
        try {
            if (StringUtil.isEmpty(data)) return;
            Serializer serializer = new Persister();
            SendRegetWaitaffirm waitaffirm = serializer.read(SendRegetWaitaffirm.class, new StringReader(data));
            if (waitaffirm.getWaitaffirm() == null) return;
            for (SendRegetWaitaffirmDTO dto : waitaffirm.getWaitaffirm()) {
                WaitaffirmVO waitaffirmVO = new WaitaffirmVO();
                waitaffirmVO.setWaitaffirmVO(dto);
                this.saveRegetWaitaffirm(waitaffirmVO);
            }
        } catch (Exception e) {
            logger.info("更新财政已对账待查失败：" + e.toString(), e);
        }
    }

    /**
     * 结束财政返回已对账待查，V2.2
     * @param data 报文
     * @param info
     * @param sn
     */
    public void sendRegetNewWaitaffirm(String data, String info, String sn) {
        try {
            if (StringUtil.isEmpty(data)) return;
            Serializer serializer = new Persister();
            SendRegetNewWaitaffirm waitaffirm = serializer.read(SendRegetNewWaitaffirm.class, new StringReader(data));
            if (waitaffirm.getWaitaffirm() == null) return;
            for (SendRegetNewWaitaffirmDTO dto : waitaffirm.getWaitaffirm()) {
                WaitaffirmVO waitaffirmVO = new WaitaffirmVO();
                waitaffirmVO.setNewWaitaffirmVO(dto);
                this.saveRegetWaitaffirm(waitaffirmVO);
            }
        } catch (Exception e) {
            logger.info("更新财政已对账待查失败：" + e.toString(), e);
        }
    }

    private int saveRegetWaitaffirm(WaitaffirmVO waitaffirmVO) throws Exception {
        waitaffirmVO.setIsbankaffirm(1);
        WaitaffirmVO vo =waitaffirmMapper.selectSwaitaffirm(waitaffirmVO.getBankaffirm(), waitaffirmVO.getBankid(), waitaffirmVO.getPaybankdt().substring(0, 10));
        if (vo == null) {
            waitaffirmVO.setWaitaffirmid(sequenceService.getNextSeq("FSWAITAFFIRMSEQ"));
            return waitaffirmMapper.insertWaitaffirm(waitaffirmVO);
        } else {
            waitaffirmVO.setPaybankdt(vo.getPaybankdt());
            return waitaffirmMapper.updateWaitaffirmByReget(waitaffirmVO);
        }
    }

    /**
     * 补充财政端已对账待查，api接口调用
     * @author hlp
     * @date 2023/2/6 08:57
     * @Description: 修改证书配置表信息
     */
    public BaseResult resetWaitaffirmInfo(WaitaffirmVO waitaffirm) {
        try {
            BankVO bank = bankMapper.findBankVO(waitaffirm.getAccountcode());
            if (bank == null) return new BaseResult(ErrorCodeEnum.CUSTOM_ERR.getCode(), "账号不存在");

            waitaffirm.setBankid(bank.getBankid());
            waitaffirm.setCantonid(bank.getCantonid());
            waitaffirm.setPaybankdt(waitaffirm.getPaybankdt().substring(0, 10));
            // 更新本地
            if (waitaffirmMapper.updateWaitaffirmReset(waitaffirm) > 0) {
                List<BankStationVO> stationList = baseDataMapper.findBankStationView(null, 1);
                return this.resetWaitaffirmInfoSend(waitaffirm, stationList);
            } else {
                return new BaseResult(ErrorCodeEnum.CUSTOM_ERR.getCode(), "更新本地数据失败");
            }
        } catch (Exception e) {
            logger.info("失败：" + e.toString(), e);
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }

    }

    /**
     * 补充财政端已对账待查，web
     * @param billids id列表
     * @return
     */
    public BaseResult resetWaitaffirmInfoByIds(String billids){
        String[] ids = billids.split(",");
        //  根据(bankid 银行帐户ID)  、(paybankdt 收款时间) 查询银行上传待查表
        List<WaitaffirmVO> list = waitaffirmMapper.findWaitaffirmByIds(ids);
        List<BankStationVO> stationList = baseDataMapper.findBankStationView(null, 1);
        for (WaitaffirmVO vo : list) {
            this.resetWaitaffirmInfoSend(vo, stationList);
        }
        return new BaseResult();
    }

    /** 补充财政端已对账待查，发送财政 */
    private BaseResult resetWaitaffirmInfoSend(WaitaffirmVO waitaffirm, List<BankStationVO> stationList) {
        try {
            long messageid = sequenceService.getNextSeq("ELEMESSAGESEQ");

            String paybankdt = waitaffirm.getPaybankdt();
            if(paybankdt.length() > 10) {
                paybankdt=paybankdt.substring(0,10);
                waitaffirm.setPaybankdt(paybankdt);
            }
            for (BankStationVO vo : stationList) {
                if (vo.getBankstationcode().equals(waitaffirm.getBankstation())) {
                    waitaffirm.setBankstation(vo.getBankstationname());
                    break;
                }
            }

            //发送到财政
            messageService.sendMessage("RESETWAITAFFIRMINFO", messageid,waitaffirm.getResetWaitaffirmInfo(), "2.2");
            return new BaseResult();
        } catch (Exception e) {
            logger.info("失败："+e.toString(), e);
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }
    }

    /**
     * 缴款书列表导出
     * @return
     */
    public void waitaffirmExport(String accountcode, String paybankdt, HttpServletResponse response) throws IOException {
        WaitaffirmVO vo = new WaitaffirmVO();
        vo.setAccountcode(accountcode);
        vo.setPaybankdt(paybankdt);
        List<WaitaffirmVO> list = waitaffirmMapper.findWaitAffirmPage(vo);

        String[] headers = {"待查id","流水号","区划id","区划编码","区划名称","缴款人","缴款人账号","缴款人开户行","收款银行开户行","收款账户","收款账号","金额","银行收款日期","银行网点","银行交易流水号","缴款方式","单据状态","发送时间","__status","银行id","银行核心交易流水号","附言","是否发送"};
        //数据键名或者MODEL类字段名
        String[] col = {"waitaffirmid","waitaffirmid","cantonid","cantoncode","cantonname","payer","payeraccount","payerbank","payeebankname","payeeaccountcode","payeeaccountname","originfund","paybankdt","bankstation","bankaffirm","payway","billstate","sendtime","billstate","bankid","hxbankaffirm","postscript","issend"};
        ExportSXSSFUtil ex = new ExportSXSSFUtil();
        SXSSFWorkbook workbook = ex.exportExcelSXSSF("待查列表", headers, col, list, null);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename="+ new String(("待查列表.xls").getBytes(), "iso-8859-1"));
        OutputStream ouputStream = response.getOutputStream();
        workbook.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();

    }

    public BaseResult regetWaitaffirmHandPay(Map data, UserVO userVO) {
        try {
            String paybankdt = data.get("paybankdt1")!=null?data.get("paybankdt1").toString():"";
            String bankaffirm = data.get("bankaffirm1")!=null?data.get("bankaffirm1").toString():"";
            String paywaycode = data.get("paywaycode")!=null?data.get("paywaycode").toString():"";
            String eticketnum = data.get("eticketnum")!=null?data.get("eticketnum").toString():"";
            BankStationVO bankStationVO = baseDataMapper.getBankStation(userVO.getBankStationId());

            String list_xml = chargeBillService.createListXml(data);
            StringBuffer buf = new StringBuffer();
            buf.append("<bill>");
            buf.append("<keyword>82</keyword>");
            buf.append("<billnum>");
            buf.append(data.get("billnum")!=null?data.get("billnum").toString():"");
            buf.append("</billnum>");
            buf.append("<eticketnum>"+eticketnum+"</eticketnum>");
            buf.append("<cantonid>");
            buf.append(data.get("cantonid")!=null?data.get("cantonid").toString():"");
            buf.append("</cantonid>");
            buf.append("<unitid>");
            buf.append(data.get("unitid")!=null?data.get("unitid").toString():"");
            buf.append("</unitid>");
            buf.append("<hallid></hallid>");
            buf.append("<filldate>");
            buf.append(data.get("filldate")!=null?data.get("filldate").toString():"");
            buf.append("</filldate>");
            buf.append("<payer>");
            buf.append(data.get("payer")!=null?data.get("payer").toString():"");
            buf.append("</payer>");
            buf.append("<payeraccount>");
            buf.append(data.get("payeraccount")!=null?data.get("payeraccount").toString():"");
            buf.append("</payeraccount>");
            buf.append("<payerbank>");
            buf.append(data.get("payerbank")!=null?data.get("payerbank").toString():"");
            buf.append("</payerbank>");
            buf.append("<bankid>");
            buf.append(data.get("bankid")!=null?data.get("bankid").toString():"");
            buf.append("</bankid>");
            buf.append("<payee>");
            buf.append(data.get("payee")!=null?data.get("payee").toString():"");
            buf.append("</payee>");
            buf.append("<payeeaccount>");
            buf.append(data.get("payeeaccount")!=null?data.get("payeeaccount").toString():"");
            buf.append("</payeeaccount>");
            buf.append("<payeebank>");
            buf.append(data.get("payeebank")!=null?data.get("payeebank").toString():"");
            buf.append("</payeebank>");
            buf.append("<memo></memo>");
            buf.append("<vertifycode></vertifycode>");
            buf.append("<originfund>");
            buf.append(data.get("originfund")!=null?data.get("originfund").toString():"");
            buf.append("</originfund>");
            buf.append("<isscale>0</isscale>");
            buf.append("<ishand>1</ishand>");
            /////////////////
            buf.append("<paybankdt>");
            buf.append(paybankdt);
            buf.append("</paybankdt>");
            buf.append("<bankaffirm>");
            buf.append(bankaffirm);
            buf.append("</bankaffirm>");
            buf.append("<bankstation>"+bankStationVO.getBankstationname()+"</bankstation>");
            buf.append("<paywayid>");
            buf.append(paywaycode);
            buf.append("</paywayid>");
            ////////////////////////////////
            buf.append("<iswaitaffirm>1</iswaitaffirm>");
            buf.append("<writename>");
            buf.append(userVO.getUserName());
            buf.append("</writename>");
            buf.append("<writedate>");
            buf.append(GTimeUtil.getDateMark());
            buf.append("</writedate>");
            buf.append("<details>");
            buf.append(list_xml);
            buf.append("</details>");
            buf.append("</bill>");
            String xml = buf.toString();
            System.out.println("create xml="+xml);
            return chargeBillService.setChargeBillManual(xml, "");

        } catch (Exception e) {
            e.printStackTrace();
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }
    }

    public BaseResult findWaitaffirm(WaitaffirmVO waitaffirmVO){
        //xml解析器
        Serializer serializer = new Persister();
        //xml转换器
        StringWriter sw = new StringWriter();

        try {
            waitaffirmVO.setBankaffirm(null);
            WaitaffirmXML waitaffirmXML = new WaitaffirmXML();
            ArrayList<Waitaffirm> waitaffirmReget = waitaffirmMapper.findWaitaffirmReget(waitaffirmVO);
            waitaffirmXML.setWaitaffirm(waitaffirmReget);
            serializer.write(waitaffirmXML, sw);
            return new BaseResult(sw.toString());

        } catch (Exception e) {
            logger.info("失败："+e.toString());
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }
    }

    public BaseResult saveWaitaffirmData(WaitaffirmVO waitaffirmVO,UserVO userVO){
        waitaffirmVO.setBankstation(userVO.getBankStationCode());
        //result 为0 表示收款失败
        return setWaitaffirm(waitaffirmVO);
    }

}